package com.study.socket.notblock;

import java.io.IOException;
import java.net.InetSocketAddress;
import java.nio.ByteBuffer;
import java.nio.channels.SocketChannel;
import java.util.Date;

/**
 * @author 朝花不迟暮
 * @version 1.0
 * @date 2020/9/27 20:09
 */
public class Client
{
    public static void main(String[] args) throws IOException
    {
        SocketChannel open = SocketChannel.open(new InetSocketAddress("127.0.0.1", 9898));
        //是否阻塞，false:非阻塞
        open.configureBlocking(false);
        ByteBuffer byteBuffer = ByteBuffer.allocate(1024);
        byteBuffer.put(new Date().toString().getBytes());
        byteBuffer.flip();
        open.write(byteBuffer);
        byteBuffer.clear();
        open.close();
    }
}
